/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
typedef long long LL;
class Solution {
public:
    long long kthLargestLevelSum(TreeNode* root, int k) {
        vector<LL>ans;
        vector<TreeNode*>q;
        q.push_back(root);
        ans.push_back(root->val);
        while (q.size()) {
            LL res = 0;
            vector<TreeNode*>q1;
            for (auto x : q) {
                if (x->left)q1.push_back(x->left), res += x->left->val;
                if (x->right)q1.push_back(x->right), res += x->right->val;
            }
            ans.push_back(res);
            cout << "res==" << res << endl;
            q = move(q1);
        }
        sort(ans.begin(), ans.end(), [&](LL a, LL b) {
            return a > b;
            });
        int len = ans.size();
        len--;
        cout << "len==" << len << endl;
        return k > len ? -1 : ans[k - 1];
    }
};